package com.zh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zh.common.QueryPageParam;
import com.zh.common.Result;
import com.zh.entity.GoodsType;
import com.zh.entity.Record;
import com.zh.mapper.GoodsTypeMapper;
import com.zh.service.GoodsTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zh
 * @since 2025-04-06
 */
@Service
public class GoodsTypeServiceImpl extends ServiceImpl<GoodsTypeMapper, GoodsType> implements GoodsTypeService {

    @Override
    public Result listPage(QueryPageParam queryPageParam) {
        HashMap param = queryPageParam.getParam();
        LambdaQueryWrapper<GoodsType> wrapper = new LambdaQueryWrapper<>();

        // 分页查询
        Page<GoodsType> page = new Page<>(
                queryPageParam.getPageNum(),
                queryPageParam.getPageSize()
        );
        if (param != null) {
            String name = (String) param.get("name");
            if (name != null) {
                wrapper.like(GoodsType::getName, name);
            }
        }


        IPage<GoodsType> result = this.page(page, wrapper);

        return Result.success(result.getRecords(), result.getTotal());
    }
}
